<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/17
 * Time: 11:12
 */
defined('IN_TS') or die('Access Denied.');

$userid = aac('user')->isLogin();

switch($ts){

    case "comment":

        $taskid = intval($_GET['taskid']);

        $commentid = intval($_GET['commentid']);

        $strComment = $new['task']->find('task_comment',array(

            'commentid'=>$commentid,
            'taskid'=>$taskid,

        ));

        if($strComment=='') tsNotice('非法操作');

        $strTask = $new['task']->find('task',array(
            'taskid'=>$taskid,
        ));

        if($strTask=='') tsNotice('非法操作！');

        if($strTask['userid']==$userid || $strComment['userid']==$userid || $TS_USER['isadmin']==1){

            $new['task']->delete('task_comment',array(
                'commentid'=>$commentid,
            ));

            tsNotice('删除成功！');

        }else{
            tsNotice('非法操作！');
        }

        break;

    case 'base':
        $taskid = intval($_GET['taskid']);

        $strTask = $new['task']->find('task',array(
            'taskid'=>$taskid,
        ));

        if ($strTask ['addtime'] < strtotime('-7 day') && $TS_USER ['isadmin'] == 0) {
            tsNotice('超过一周，不允许删除，如有需要请给微澜图书馆公众号后台留言');
        }
        if ($strTask ['userid']!=$TS_USER ['userid'] && $TS_USER ['isadmin'] == 0) {
            tsNotice('没有操作权限');
        }
        if($strTask['photo']){
            unlink('uploadfile/task/'.$strTask['photo']);
        }

        $new['task']->delete('task',array(
            'taskid'=>$taskid,
        ));

        $new['task']->delete('task_comment',array(
            'taskid'=>$taskid,
        ));

        $new['task']->delete('task_users',array(
            'taskid'=>$taskid,
        ));

        tsNotice('删除成功!');

        break;

}